package com.kiragame.couplescreen;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class KiraMessage {
	private MessageType messageType;
	private String content;
	private String error;

	public MessageType getMessageType() {
		return messageType;
	}

	public void setMessageType(MessageType messageType) {
		this.messageType = messageType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static KiraMessage fromJsonToKiraMessage(String json) {
		return new JSONDeserializer<KiraMessage>().use(null, KiraMessage.class)
				.deserialize(json);
	}

	public static String toJsonArray(Collection<KiraMessage> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<KiraMessage> fromJsonArrayToKiraMessages(
			String json) {
		return new JSONDeserializer<List<KiraMessage>>()
				.use(null, ArrayList.class).use("values", KiraMessage.class)
				.deserialize(json);
	}

	public enum MessageType {
		SEND_REQUEST, SEND_FILE
	}
}
